from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-29 14:03:55.165171
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 29, Aug, 2022
Time: 14:04:01
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.2465
Nobs: 763.000 HQIC: -50.5829
Log likelihood: 9723.86 FPE: 8.72320e-23
AIC: -50.7935 Det(Omega_mle): 7.75856e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300398 0.054806 5.481 0.000
L1.Burgenland 0.106648 0.036433 2.927 0.003
L1.Kärnten -0.106788 0.019360 -5.516 0.000
L1.Niederösterreich 0.206461 0.076140 2.712 0.007
L1.Oberösterreich 0.113848 0.073846 1.542 0.123
L1.Salzburg 0.252653 0.038994 6.479 0.000
L1.Steiermark 0.035741 0.050856 0.703 0.482
L1.Tirol 0.106890 0.041176 2.596 0.009
L1.Vorarlberg -0.060777 0.035403 -1.717 0.086
L1.Wien 0.049801 0.065633 0.759 0.448
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061042 0.113854 0.536 0.592
L1.Burgenland -0.034822 0.075687 -0.460 0.645
L1.Kärnten 0.047355 0.040219 1.177 0.239
L1.Niederösterreich -0.173365 0.158175 -1.096 0.273
L1.Oberösterreich 0.396641 0.153409 2.586 0.010
L1.Salzburg 0.289781 0.081006 3.577 0.000
L1.Steiermark 0.104888 0.105648 0.993 0.321
L1.Tirol 0.314113 0.085540 3.672 0.000
L1.Vorarlberg 0.026717 0.073547 0.363 0.716
L1.Wien -0.024974 0.136347 -0.183 0.855
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191302 0.028180 6.789 0.000
L1.Burgenland 0.089557 0.018733 4.781 0.000
L1.Kärnten -0.008713 0.009954 -0.875 0.381
L1.Niederösterreich 0.259736 0.039149 6.634 0.000
L1.Oberösterreich 0.134775 0.037970 3.550 0.000
L1.Salzburg 0.045837 0.020050 2.286 0.022
L1.Steiermark 0.017265 0.026149 0.660 0.509
L1.Tirol 0.093684 0.021172 4.425 0.000
L1.Vorarlberg 0.058309 0.018204 3.203 0.001
L1.Wien 0.119355 0.033747 3.537 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107973 0.028620 3.773 0.000
L1.Burgenland 0.047432 0.019026 2.493 0.013
L1.Kärnten -0.014678 0.010110 -1.452 0.147
L1.Niederösterreich 0.192372 0.039761 4.838 0.000
L1.Oberösterreich 0.289813 0.038563 7.515 0.000
L1.Salzburg 0.111858 0.020363 5.493 0.000
L1.Steiermark 0.102245 0.026557 3.850 0.000
L1.Tirol 0.110386 0.021503 5.134 0.000
L1.Vorarlberg 0.069538 0.018488 3.761 0.000
L1.Wien -0.017678 0.034274 -0.516 0.606
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130774 0.051967 2.516 0.012
L1.Burgenland -0.051752 0.034546 -1.498 0.134
L1.Kärnten -0.040244 0.018357 -2.192 0.028
L1.Niederösterreich 0.170577 0.072197 2.363 0.018
L1.Oberösterreich 0.141197 0.070021 2.016 0.044
L1.Salzburg 0.288028 0.036974 7.790 0.000
L1.Steiermark 0.031857 0.048222 0.661 0.509
L1.Tirol 0.161631 0.039044 4.140 0.000
L1.Vorarlberg 0.100754 0.033570 3.001 0.003
L1.Wien 0.069168 0.062234 1.111 0.266
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056290 0.041396 1.360 0.174
L1.Burgenland 0.040357 0.027519 1.466 0.143
L1.Kärnten 0.050285 0.014623 3.439 0.001
L1.Niederösterreich 0.220591 0.057511 3.836 0.000
L1.Oberösterreich 0.283630 0.055778 5.085 0.000
L1.Salzburg 0.045808 0.029453 1.555 0.120
L1.Steiermark -0.001058 0.038413 -0.028 0.978
L1.Tirol 0.148123 0.031102 4.763 0.000
L1.Vorarlberg 0.072543 0.026741 2.713 0.007
L1.Wien 0.084247 0.049575 1.699 0.089
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180302 0.049574 3.637 0.000
L1.Burgenland -0.005789 0.032956 -0.176 0.861
L1.Kärnten -0.061407 0.017512 -3.507 0.000
L1.Niederösterreich -0.082881 0.068873 -1.203 0.229
L1.Oberösterreich 0.197273 0.066797 2.953 0.003
L1.Salzburg 0.056191 0.035272 1.593 0.111
L1.Steiermark 0.230675 0.046001 5.015 0.000
L1.Tirol 0.493895 0.037246 13.260 0.000
L1.Vorarlberg 0.047598 0.032024 1.486 0.137
L1.Wien -0.053645 0.059368 -0.904 0.366
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166503 0.056929 2.925 0.003
L1.Burgenland -0.010468 0.037845 -0.277 0.782
L1.Kärnten 0.067160 0.020110 3.340 0.001
L1.Niederösterreich 0.206703 0.079091 2.613 0.009
L1.Oberösterreich -0.070714 0.076707 -0.922 0.357
L1.Salzburg 0.211440 0.040505 5.220 0.000
L1.Steiermark 0.115698 0.052826 2.190 0.029
L1.Tirol 0.071689 0.042772 1.676 0.094
L1.Vorarlberg 0.121559 0.036775 3.305 0.001
L1.Wien 0.122057 0.068176 1.790 0.073
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359823 0.032863 10.949 0.000
L1.Burgenland 0.005733 0.021846 0.262 0.793
L1.Kärnten -0.023356 0.011609 -2.012 0.044
L1.Niederösterreich 0.213988 0.045655 4.687 0.000
L1.Oberösterreich 0.191001 0.044279 4.314 0.000
L1.Salzburg 0.045679 0.023381 1.954 0.051
L1.Steiermark -0.016395 0.030494 -0.538 0.591
L1.Tirol 0.106250 0.024690 4.303 0.000
L1.Vorarlberg 0.073384 0.021228 3.457 0.001
L1.Wien 0.045476 0.039355 1.156 0.248
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040249 0.148599 0.191989 0.157794 0.123922 0.112803 0.065913 0.221760
Kärnten 0.040249 1.000000 -0.004239 0.133155 0.040935 0.095847 0.430988 -0.052332 0.100020
Niederösterreich 0.148599 -0.004239 1.000000 0.337419 0.149754 0.298951 0.107427 0.183091 0.322471
Oberösterreich 0.191989 0.133155 0.337419 1.000000 0.227778 0.330998 0.172539 0.168059 0.264979
Salzburg 0.157794 0.040935 0.149754 0.227778 1.000000 0.147188 0.122496 0.147606 0.131545
Steiermark 0.123922 0.095847 0.298951 0.330998 0.147188 1.000000 0.150906 0.138208 0.079251
Tirol 0.112803 0.430988 0.107427 0.172539 0.122496 0.150906 1.000000 0.114950 0.152059
Vorarlberg 0.065913 -0.052332 0.183091 0.168059 0.147606 0.138208 0.114950 1.000000 0.006573
Wien 0.221760 0.100020 0.322471 0.264979 0.131545 0.079251 0.152059 0.006573 1.000000